package com.example.warehouse.bus.controller;

import com.alibaba.druid.sql.dialect.oscar.visitor.OscarPermissionOutputVisitor;
import com.example.warehouse.bus.pojo.param.BusBreakRequestParam;
import com.example.warehouse.bus.pojo.param.BusBreakageQueryParam;
import com.example.warehouse.bus.service.IBusBreakageService;
import com.example.warehouse.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 处理报损商品的控制器，这里主要是做一个报损清单的功能
 */
@RestController
@Slf4j
@Api(tags = "8.1 清单管理模块")
@RequestMapping("breakage")
public class BusBreakageController {
    @Autowired
    private IBusBreakageService ibbs;
    @ApiOperation("显示报损清单")
    @ApiOperationSupport(order = 100)
    @GetMapping("show")
    public JsonResult inventory(Integer pageNum)
    {
        log.debug("控制器开始处理显示报损清单的请求！");
        return JsonResult.ok(ibbs.pageHelperByPageNum(pageNum));
    }
    @ApiOperation("报损确认")
    @ApiOperationSupport(order = 200)
    @PostMapping("affirm")
    public JsonResult breakageAffirm(BusBreakRequestParam busBreakRequestParam)
    {
        log.debug("控制器开始处理显示报损的请求,请求参数是:{}",busBreakRequestParam);
        ibbs.breakageRequest(busBreakRequestParam);
        return JsonResult.ok();
    }
    @ApiOperation("关键字查询")
    @ApiOperationSupport(order = 300)
    @GetMapping("query-type")
    public JsonResult inventory(Integer select,String input,Integer pageNum)
    {
        if(pageNum==null||pageNum<1)
        {
            pageNum=1;
        }
        BusBreakageQueryParam busBreakageQueryParam=new BusBreakageQueryParam();
        log.debug("控制器开始处理根据类型查询报损清单的请求！");
        if(select==1)
        {
            busBreakageQueryParam.setGoodsName(input);
        }
        if(select==2)
        {
            busBreakageQueryParam.setProviderName(input);
        }
       if(select==3)
       {
           busBreakageQueryParam.setSubmitName(input);
       }
        return JsonResult.ok(ibbs.findByKeywordAndTypeFuzzyQuery(busBreakageQueryParam,pageNum));
    }
}
